<html>
<head>
<!-- CSS goes in the document HEAD or added to your external stylesheet -->
<link rel="stylesheet" href="styles/staff.css" type="text/css" />
<script type="text/javascript">
function checkall(class_name, obj) {
		//Duyệt qua các checkbox có class = class_name (item)
		//Trả về các phần tử ở dạng mảng, bắt dầu từ vị trí 0;
		var items = document.getElementsByClassName(class_name);
		if(obj.checked == true) //Đã được chọn
		{
			for(i=0; i < items.length ; i++)
				items[i].checked = true;
		}
		else { //Checkbox chưa được chọn
			for(i=0; i < items.length ; i++)
				items[i].checked = false;
		}
	}
</script>
</head>
<body>
<?php //BEGIN: Thanh
include_once ('control/student-proc.php');
function renderSelectClassDropdown($name,$classIDs) {
	echo "<select name='".$name."'>";
	foreach($classIDs as $classID) {
		renderOpptionTag(calStudentYear($classID),strtoupper($classID),false);
	}
	echo "</select>";
}

//END?>
<?php
if(isset($_SESSION["openclass-error"])){
    echo($_SESSION["openclass-error"]);
    unset($_SESSION["openclass-error"]);
}
require("model/connect.php");

$idtrainningpro = $_GET['idtrainningpro']; 
  
$temp = new TrainningClass(null,null,null);
$listClasses = $temp->getIDOfClassInProgram($idtrainningpro);

$baitren_mottrang = 10;

if ( !isset($_GET['page']) )
{
    $page = 0 ;

}else
{
    $page= $_GET['page'];
}

$sodu_lieu = mysql_num_rows(mysql_query("SELECT c.COURSE_ID,c.COURSE_NAME,c.COURSE_CREDIT,t.TRNP_ID,t.SECOND_COURSE_ID FROM course c inner join courserelationship t ON c.COURSE_ID = t.COURSE_ID WHERE c.COURSE_ID NOT IN (SELECT COURSE_ID FROM trainningitem WHERE TRNP_ID like '".$idtrainningpro."') AND t.TRNP_ID = '".$idtrainningpro."'") ) or die(mysql_error());

$sotrang = $sodu_lieu/$baitren_mottrang;

   $result =mysql_query("SELECT c.COURSE_ID,c.COURSE_NAME,c.COURSE_CREDIT,t.TRNP_ID,t.SECOND_COURSE_ID FROM course c inner join courserelationship t ON c.COURSE_ID = t.COURSE_ID WHERE c.COURSE_ID NOT IN (SELECT COURSE_ID FROM trainningitem WHERE TRNP_ID like '".$idtrainningpro."') AND t.TRNP_ID = '".$idtrainningpro."' LIMIT ".$page*$baitren_mottrang.",".$baitren_mottrang) or die(mysql_error());
 
?>
<table class="gridtable" >
    <form action="control/staff-proc-open-class.php" method="POST">
    <tr>
        <th>Mã môn học</th>
        <th>tên môn học</th>
        <th>Số tín chỉ</th>
        <th>Khoa quản lý</th>
        <th>Lớp học gợi ý</th>
        <th>Môn tiên quyết</th>
        <th><input type="checkbox" onClick="checkall('item', this)" name="check" class="checkbox" />Mở tất cả</th>
    </tr>
    <?php
    while ( $info = mysql_fetch_array($result )) 
    {
        ?>
    <tr>
        <td><?php echo $info[0].""  ?></td>
        <td><?php echo $info[1].""  ?></td>
        <td><?php echo $info[2].""  ?></td>
        <td><?php echo $info[3].""  ?></td>
        <td><?php renderSelectClassDropdown("class".$info[0],$listClasses)?></td>
        <td><?php echo $info[4].""  ?></td>
        <td><?php echo "<input type=\"checkbox\" class=\"item\" name=\"checkid[]\" class=\"checkbox\" value=\"{$info[0]}\"/> "  ?>Mở lớp</td>
    </tr>
        <?php
    }
    echo "<input type=\"hidden\" name=\"idtrainningpro\" value=\"{$idtrainningpro}\" />";
    ?>
    
    <input type="submit" value="Mở lớp" />   <? echo "  cho ".$idtrainningpro; ?> 
    </form>
</table>

<?php
for ( $page = 0; $page < $sotrang; $page ++ )
{
echo "<a href='staff-index.php?idtrainningpro={$idtrainningpro}&p=staff-list-course&page={$page}'> {$page} </a>";
} 

mysql_close();
?>
</body>
</html>

